package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

/**
 * 平台后台 - 会员支付策略 - 关联的支付方式
 * @author 万宁
 * @version 2.0.0
 * @date 2021-08-11
 */
@Entity
@Table(schema = "public", name = "ord_platform_payment_type", indexes = {@Index(name = "ord_platform_payment_type_payment_id_idx", columnList = "payment_id"), @Index(name = "ord_platform_payment_type_pay_type_idx", columnList = "payType")})
public class PlatformPaymentTypeDO implements Serializable {
    private static final long serialVersionUID = 8589390202667035245L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_platform_payment_type_seq")
    @SequenceGenerator(sequenceName = "ord_platform_payment_type_seq", name = "ord_platform_payment_type_seq", allocationSize = 1)
    private Long id;

    /**
     * 多对一双向关联会员支付策略配置
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "payment_id")
    private PlatformPaymentDO payment;

    /**
     * 资金归集模式，定义在 FundModeEnum 中
     */
    @Column
    private Integer fundMode;

    /**
     * 支付方式，定义在 OrderPayTypeEnum 中
     */
    @Column
    private Integer payType;

    /**
     * 支付方式名称
     */
    @Column(columnDefinition = "varchar(20)")
    private String payTypeName;

    /**
     * 一对多双向关联支付渠道
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "payType", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<PlatformPaymentChannelDO> payChannels;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public PlatformPaymentDO getPayment() {
        return payment;
    }

    public void setPayment(PlatformPaymentDO payment) {
        this.payment = payment;
    }

    public Integer getFundMode() {
        return fundMode;
    }

    public void setFundMode(Integer fundMode) {
        this.fundMode = fundMode;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public String getPayTypeName() {
        return payTypeName;
    }

    public void setPayTypeName(String payTypeName) {
        this.payTypeName = payTypeName;
    }

    public Set<PlatformPaymentChannelDO> getPayChannels() {
        return payChannels;
    }

    public void setPayChannels(Set<PlatformPaymentChannelDO> payChannels) {
        this.payChannels = payChannels;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        PlatformPaymentTypeDO that = (PlatformPaymentTypeDO) o;
        return id.equals(that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
